package pers.feng1240.blog.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.chainsaw.Main;
import org.springframework.stereotype.Service;

import pers.feng1240.blog.dao.ThemeDao;
import pers.feng1240.blog.entities.Theme;
import pers.feng1240.blog.service.ThemeService;
import pers.feng1240.blog.util.PageHelper;

/*
 * 主题逻辑实现
 */
@Service("themeService")
public class ThemeServiceImpl implements ThemeService {

	@Resource
	private ThemeDao themeDao;//数据访问层
	
	/*
	 * 添加主题
	 * @see pers.feng1240.blog.service.ThemeService#addTheme(pers.feng1240.blog.entities.Theme)
	 */
	public void addObject(Object theme) {
		// TODO Auto-generated method stub
		themeDao.addObject(theme);
	}

	/*
	 * 列表
	 * see pers.feng1240.blog.service.AbstractService#getObjectList()
	 */
	public List<Object> getObjectList() {
		return themeDao.getObjectList();
	}
	
	/*
	 * 列表分页
	 * @see pers.feng1240.blog.service.AbstractService#getPageList(String)
	 * @param pageIndex 要获取的页码
	 */
	public Map<String,Object> getPageList(int pageIndex) {
		Map<String,Object> mapRes = new HashMap<String,Object>();
		int count = themeDao.objectCount(); //对象总个数
		mapRes.put("count", count);
		mapRes.put("pageSize", PageHelper.pageSize(count));//页数
		mapRes.put("pageIndex", pageIndex); //
		mapRes.put("objectList", themeDao.getPageList(PageHelper.selObj(pageIndex)));
		return mapRes;
	}

	/*
	 * 根据id 查看一条
	 * @see pers.feng1240.blog.service.AbstractService#getObject(int)
	 */
	public Object getById(int id) {
		// TODO Auto-generated method stub
		return themeDao.getById(id);
	}

	/*
	 * 编辑更新
	 * @see pers.feng1240.blog.service.AbstractService#updataObject(java.lang.Object)
	 */
	public void updateObject(Object theme) {
		// TODO Auto-generated method stub
		themeDao.updateObject(theme);
	}

	/*
	 * 删除
	 * @see pers.feng1240.blog.service.AbstractService#deleteById(int)
	 */
	public void deleteById(int id) {
		themeDao.deleteById(id);
		
	}
	
}
